package com.example.demo08;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
import android.os.Bundle;
import android.view.View;

public class WifiPage extends BaseTextPage {

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		appendn("wifi扫描结果");
		
		WifiManager wm = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
		List<ScanResult> srs = wm.getScanResults();
		if(srs != null && !srs.isEmpty()) {
			for(ScanResult sr : srs) {
				StringBuilder sb = new StringBuilder();
				sb.append(sr.SSID).append("-----------").append('\n');
				try {
					Field[] fs = ScanResult.class.getDeclaredFields();
					for(Field f : fs) {
						f.setAccessible(true);
						sb.append("  ").append(f.getName()).append("=").append(f.get(sr)).append('\n');
					}
				} catch (Exception e) {
				}
				
				appendn(sb.toString());
			}
		} else
			appendn("WIFI SCAN EMPTY");
		
		try {
			Constructor<?>[] cs = ScanResult.class.getDeclaredConstructors();
			
			System.out.println(cs[0]);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		update();
	}
}
